package com.gadgets.busi.bm02.service;

import com.gadgets.busi.bm02.dto.Ck3ModifyDictAddDTO;
import com.gadgets.busi.bm02.dto.Ck3ModifyDictQueryDTO;
import com.gadgets.busi.bm02.pojo.Ck3ModifyDict;
import com.gadgets.busi.bm02.repository.ICk3ModifyDict;
import com.gadgets.framework.common.dto.Pagination;
import com.gadgets.framework.common.exception.GadgetsServiceException;
import com.gadgets.framework.common.util.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED, transactionManager = "gadgetsDbTransactionManage")
public class Ck3ServiceImpl implements ICk3Service {

    @Autowired
    private ICk3ModifyDict ck3ModifyDict;

    /**
     * 生成 Ck3 初始修正
     *
     * @param ck3ModifyDTO 修正列表
     * @throws GadgetsServiceException 异常信息
     */
    @Override
    @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED, transactionManager = "gadgetsDbTransactionManage")
    public void generatorCk3Modify(Ck3ModifyDictAddDTO ck3ModifyDTO) throws GadgetsServiceException {
        Ck3ModifyDict dict = new Ck3ModifyDict();
        dict.setModifyType(ck3ModifyDTO.getModifyType());
        dict.setModifyName(ck3ModifyDTO.getModifyName());
        dict.setModifyGroup(ck3ModifyDTO.getModifyGroup());
        dict.setReserve1(ck3ModifyDTO.getReserve1());
        dict.setReserve3(ck3ModifyDTO.getReserve3());
        dict.setModifyCode(ck3ModifyDTO.getModifyCode());
        dict.setReserve2(ck3ModifyDTO.getReserve2());
        ck3ModifyDict.insertCk3ModifyDict(dict);
    }

    /**
     * 分页条件查询 Ck3 初始修正列表
     *
     * @param queryDTO   查询条件
     * @param pagination 分页条件
     * @return 查询结果
     * @throws GadgetsServiceException 异常信息
     */
    @Override
    @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED, transactionManager = "gadgetsDbTransactionManage")
    public List<Ck3ModifyDict> queryCk3ModiftDict(Ck3ModifyDictQueryDTO queryDTO, Pagination pagination) throws GadgetsServiceException {
        PaginationUtil.bulidPaginationInfo(pagination);
        List<Ck3ModifyDict> list = ck3ModifyDict.selectCk3ModifyDictByCondition(queryDTO);
        PaginationUtil.getPaginationResultInfo(list, pagination);
        return list;
    }
}
